package io.renren.modules.work.controller;

import io.renren.common.utils.R;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.sys.entity.SysUserEntity;
import io.renren.modules.work.service.InStockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author: liguanghao
 * @Date: 2019/10/15 11:32
 * @Version 1.0
 */
@Api(description = "入 库任务")
@RestController("/inStock/controller")
public class InStockController extends AbstractController {

    @Autowired
    private InStockService inStockService;

    @ApiOperation(value = "入库总任务下发",notes = "入库总任务下发")
    @PostMapping("/check/in/for/main/task")
    public R checkInForMainTask(@RequestBody Map<String,Object> params){
        /**
         * 需要的参数
         * way  库位分配方式
         * doorWay  出入口
         * taskRunInfoId    主任务id
         * warehousRankId   手动选择的库位id
         */
        SysUserEntity user = this.getUser();
        String doorWay = user.getDoorWay();
        params.put("doorWay",doorWay);
       return inStockService.checkInForMainTask(params);
    }

    @ApiOperation(value = "执行子任务",notes="执行子任务")
    @PostMapping("/run/in/for/child/task")
    public R runInForChildTask(@RequestBody Map<String,Object> params){
        /**
         * way  库位分配方式
         * taskRunInfoDetId     子任务id
         * warehousRankId       手动选择的库位id
         * quantity             输入的数量
         * doorWay  出入口
         * model    产品名称
         * unit     单位
         */
        return inStockService.runInForChildTask(params);
    }
    @ApiOperation(value = "任务加入待执行队列",notes="任务加入待执行队列")
    @PostMapping("/join/wait/queue")
    public R joinWaitQueue(@RequestBody Integer id){
        /**
         * id     任务id
         */
        return inStockService.joinWaitQueue(id);
    }
    @ApiOperation(value = "任务退出待执行队列",notes="任务退出待执行队列")
    @PostMapping("/exit/wait/queue")
    public R exitWaitQueue(@RequestBody Integer id){
        /**
         * id     任务id
         */
        return inStockService.exitWaitQueue(id);
    }
}
